package com.koyi0000.mq.rabbit;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

/**
 * @author koyi0000
 * Description  Date 2020/9/23 19:38
 **/
public class testBloomFilter {

    private static int size = 1000000;// 预计插入多少数据

    private static  double fpp = 0.00001; // 期望的误判率，误判率不能为0
    private static BloomFilter<Integer> bloomFilter = BloomFilter.create(Funnels.integerFunnel(), size, fpp);

    public static void main(String[] args) {
        // 插入数据
        for(int i = 0; i < 1000000; i++) {// 会进行自动扩容
             bloomFilter.put(i);
        }
        int count = 0;
        for (int i = 1000000; i < 2000000; i++) {
            if (bloomFilter.mightContain(i)) {
                count++;
                System.out.println(i + "误判了");
            }
        }
        System.out.println("总共误判数: " + count);
    }
}
